package idv.np7sky.ocean.consumer.component.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * TODO
 *
 * @author zxw
 * @version 2.3.0
 * @date 2020-07-11 17:26
 * @since 2.3.0
 */
@Slf4j
@RestController
@RequestMapping("/consumer/project")
public class ProjectController {

    @Resource
    private RestTemplate restTemplate;

    /**
     *
     * @param projectId
     */
    @GetMapping("/detail/{projectId}")
    public String detail(@PathVariable(value = "projectId") String projectId) {
        ResponseEntity<String> forEntity = restTemplate.getForEntity("http://localhost:9090/producer/info/detail/" + projectId, String.class);
        boolean xxSuccessful = forEntity.getStatusCode().is2xxSuccessful();
        if(xxSuccessful){
            return forEntity.getBody();
        }
        return projectId+":error";
    }

}
